<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\IntegralRule;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;

class IntegralRuleController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new IntegralRule(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('intro');
            $grid->column('day_time_type')->display(function($day_time_type){
                if($day_time_type == 1){

                    return '每'.$this->day.'天'.$this->every_day_num.'次';
                }else{
                    return '只给一次';
                }
            });
            $grid->column('integral');
//            $grid->column('remark')->width('200px');
            $grid->column('status', '可用状态') ->switch();
//            $grid->column('app_title');
            $grid->column('app_icon') ->image('',60,60);
            $grid->column('app_show', 'APP内展示') ->switch();
            $grid->column('created_at')->width('200px');
        

            $grid->disableViewButton();
            $grid->disableCreateButton();
            $grid->disableDeleteButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new IntegralRule(), function (Show $show) {
            $show->field('id');
            $show->field('intro');
            $show->field('day_time_type');
            $show->field('day');
            $show->field('every_day_num');
            $show->field('integral');
            $show->field('remark');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new IntegralRule(), function (Form $form) {
            $form->display('id');
            $form->text('intro');
            $form->radio('day_time_type')
            ->when(1,function(Form $form){
                $form->number('day');
                $form->number('every_day_num');
            })
                -> options([1 => '每X天X次', 2 => '只给一次']);

            $form->number('integral');
            $form->textarea('remark');
            $form->radio('status', '可用状态') ->options([1 => '启用',0 => '停用'])->default(0);
            $form->text('app_title');
            $form->image('app_icon') ->move('app_icon/'.date('Y-m-d')) ->autoUpload();
            $form->radio('app_show', 'APP内展示') ->options([1 => '显示',0 => '隐藏']) ->default(0);
        
            $form->display('created_at');
            $form->display('updated_at');

            $form ->disableDeleteButton();
            $form ->disableViewButton();
        });
    }
}
